package com.cencat.order.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.Valid;
import jakarta.validation.constraints.*;
import lombok.Data;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 订单创建DTO
 * @author cencat
 * @description 固定商家场景多租户SaaS企业综合管理系统订单创建DTO
 * @since 2024-01-01
 */
@Data
@Schema(description = "订单创建DTO")
public class OrderCreateDTO {

    @Schema(description = "租户ID", required = true)
    @NotNull(message = "租户ID不能为空")
    private Long tenantId;

    @Schema(description = "商家ID", required = true)
    @NotNull(message = "商家ID不能为空")
    private Long merchantId;

    @Schema(description = "用户ID", required = true)
    @NotNull(message = "用户ID不能为空")
    private Long userId;

    @Schema(description = "收货人姓名", required = true)
    @NotBlank(message = "收货人姓名不能为空")
    @Size(max = 50, message = "收货人姓名长度不能超过50个字符")
    private String receiverName;

    @Schema(description = "收货人手机号", required = true)
    @NotBlank(message = "收货人手机号不能为空")
    @Pattern(regexp = "^1[3-9]\\d{9}$", message = "手机号格式不正确")
    private String receiverPhone;

    @Schema(description = "收货地址", required = true)
    @NotBlank(message = "收货地址不能为空")
    @Size(max = 200, message = "收货地址长度不能超过200个字符")
    private String receiverAddress;

    @Schema(description = "省份")
    @Size(max = 20, message = "省份长度不能超过20个字符")
    private String province;

    @Schema(description = "城市")
    @Size(max = 20, message = "城市长度不能超过20个字符")
    private String city;

    @Schema(description = "区县")
    @Size(max = 20, message = "区县长度不能超过20个字符")
    private String district;

    @Schema(description = "邮政编码")
    @Pattern(regexp = "^\\d{6}$", message = "邮政编码格式不正确")
    private String postalCode;

    @Schema(description = "订单备注")
    @Size(max = 500, message = "订单备注长度不能超过500个字符")
    private String orderRemark;

    @Schema(description = "配送方式", required = true)
    @NotBlank(message = "配送方式不能为空")
    private String deliveryMethod;

    @Schema(description = "期望配送时间")
    private LocalDateTime expectedDeliveryTime;

    @Schema(description = "支付方式")
    private String paymentMethod;

    @Schema(description = "优惠券ID")
    private Long couponId;

    @Schema(description = "使用积分")
    @Min(value = 0, message = "使用积分不能小于0")
    private Integer usePoints;

    @Schema(description = "优惠金额")
    @DecimalMin(value = "0.00", message = "优惠金额不能小于0")
    private BigDecimal discountAmount;

    @Schema(description = "订单商品列表", required = true)
    @NotEmpty(message = "订单商品列表不能为空")
    @Valid
    private List<OrderItemCreateDTO> orderItems;

    /**
     * 订单商品创建DTO
     */
    @Data
    @Schema(description = "订单商品创建DTO")
    public static class OrderItemCreateDTO {

        @Schema(description = "商品ID", required = true)
        @NotNull(message = "商品ID不能为空")
        private Long productId;

        @Schema(description = "商品规格ID")
        private Long productSpecId;

        @Schema(description = "购买数量", required = true)
        @NotNull(message = "购买数量不能为空")
        @Min(value = 1, message = "购买数量不能小于1")
        private Integer quantity;

        @Schema(description = "商品单价", required = true)
        @NotNull(message = "商品单价不能为空")
        @DecimalMin(value = "0.01", message = "商品单价不能小于0.01")
        private BigDecimal unitPrice;

        @Schema(description = "商品备注")
        @Size(max = 200, message = "商品备注长度不能超过200个字符")
        private String itemRemark;
    }
}